﻿package com.module.sysconfig.service.impl;

import java.lang.reflect.Proxy;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.module.sysconfig.dao.ZsZmxlhglMapper;
import com.module.sysconfig.service.IZsZmxlhglService;
import com.support.cache.annotation.CacheEvict;
import com.support.cache.annotation.Cacheable;
import com.support.cache.annotation.KeyMode;
import com.support.jdbc.Page;
import com.support.observer.ReloadCacheEvent;
import com.support.web.ApplicationContextSupport;

@Service("zsZmxlhglService")
public class ZsZmxlhglServiceImpl implements IZsZmxlhglService
{

	@Autowired
	private ZsZmxlhglMapper zsZmxlhglMapper;
	
    /**
     * 
     * @param params
     * @return
     */
    public void saveXtZsxlh(Map<String, String> params) throws Exception
    {
    	zsZmxlhglMapper.saveZsxlhgl(params);
    	
    }
    
    @Override
	public void deleteZsxlh(String id) throws Exception
	{
		zsZmxlhglMapper.deleteZsxlhgl(id);
	}

	@Override
	public void updateXtZsxlh(Map<String, String> params) throws Exception
	{
		zsZmxlhglMapper.updateZsxlhgl(params);
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	@Cacheable(expire=10, keyMode=KeyMode.ALL)
	public Page queryXtZsxlh(Page page) throws Exception
	{
		page.setResults(zsZmxlhglMapper.queryZsxlhgl(page));
		return page;
	}
	
	
	
	
    /**
     *
     * @param params
     * @return
     */
	@SuppressWarnings("rawtypes")
	@CacheEvict(key="queryAllXtZmxlh", keyMode=KeyMode.KEY_ONLY)
    public void saveXtZmxlh(Map<String, String> params) throws Exception
    {
    	zsZmxlhglMapper.saveZmxlhgl(params);
    	
		queryXtZmxlh(new Page());
    }

	@SuppressWarnings("rawtypes")
	@Override
	@CacheEvict(key="queryAllXtZmxlh", keyMode=KeyMode.KEY_ONLY)
	public void deleteXtZmxlh(String id) throws Exception
	{
		zsZmxlhglMapper.deleteZmxlhgl(id);

		queryXtZmxlh(new Page());
	}

	@Override
	@CacheEvict(key="queryAllXtZmxlh", keyMode=KeyMode.KEY_ONLY)
	public void updateXtZmxlh(Map<String, String> params) throws Exception
	{
		zsZmxlhglMapper.updateZmxlhgl(params);

		// 发送事件重新加载缓存 TODO
		System.out.println("serviceImpl:" + this);
		
		ApplicationContextSupport.getContext().publishEvent(new ReloadCacheEvent(this, "queryAllXtZmxlh"));
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Page queryXtZmxlh(Page page) throws Exception
	{
        Page pageResult = new Page();
        pageResult.setResults(zsZmxlhglMapper.queryZmxlh(page));
		return pageResult;
	}
	
	@Cacheable(key="queryAllXtZmxlh", keyMode=KeyMode.KEY_ONLY)
	public Page queryAllXtZmxlh() throws Exception
	{
        Page pageResult = new Page();
        pageResult.setResults(zsZmxlhglMapper.queryAllZmxlh());
		return pageResult;
	}
	
	/*@Cacheable(key="queryAllXtZmxlh", keyMode=KeyMode.KEY_ONLY)
	public Object reloadCache() throws Exception
	{
		return queryAllXtZmxlh();
	}*/
}


